﻿//-----------------------------------------------------------------------
// <copyright company="www.3WayWebdesign.de">
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//
// <author>Michael Morbach</author>
// <email>Michael@3waywebdesign.de</email>
// <web>http://www.3waywebdesign.de</web>
//-----------------------------------------------------------------------

namespace Tww.MAF.MAFMenuBarModule
{
    #region Imports

    using Microsoft.Practices.Prism.Events;
    using Microsoft.Practices.Prism.Modularity;
    using Microsoft.Practices.Prism.Regions;
    using Microsoft.Practices.Unity;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Shapes;
    using Tww.MAF.MAFInfrastructure.Interfaces.Services;
    using Tww.MAF.MAFInfrastructure.Interfaces.ViewModels;
    using Tww.MAF.MAFInfrastructure.Interfaces.Views;
    using Tww.MAF.MAFInfrastructure.Models.UI.Menu;
    using Tww.MAF.MAFMenuBarModule.Models.UI.Menu;
    using Tww.MAF.MAFMenuBarModule.Services;
    using Tww.MAF.MAFMenuBarModule.ViewModels;
    using Tww.MAF.MAFMenuBarModule.Views;


    #endregion

    public class MAFMenuBarModule : IModule
    {
        #region Ctors

        public MAFMenuBarModule( IRegionManager regionManager, IUnityContainer unityContainer )
        {
            this.RegionManager = regionManager;
            this.UnityContainer = unityContainer;
        }

        #endregion

        #region Private Properties

        protected IEventAggregator EventAggregator { get; set; }
        protected IRegionManager RegionManager { get; set; }
        protected IUnityContainer UnityContainer { get; set; }

        #endregion

        public void Initialize()
        {
            // Register universal type for IMenuTreeEntries
            this.UnityContainer.RegisterType<IMenuTreeEntry, MenuTreeEntry>();

            // Services
            this.UnityContainer.RegisterType<IMenuBarService, MenuBarService>( new ContainerControlledLifetimeManager() );

            // ViewModels & Views 
            this.UnityContainer.RegisterType<IMenuBarViewModel, MenuBarViewModel>( new ContainerControlledLifetimeManager() );
            this.UnityContainer.RegisterType<IMenuBarView, MenuBarView>();



            // Example Menu Generation

            var menuList = new List<IMenuTreeEntry>();

            for ( int i = 0; i < 3; i++ )
            {
                var tab = this.UnityContainer.Resolve<IMenuTreeEntry>();
                tab.Title = "Menu " + i.ToString();

                for ( int b = 0; b < 3; b++ )
                {
                    var subItem = this.UnityContainer.Resolve<IMenuTreeEntry>();
                    subItem.Title = "Submenu " + b.ToString();
                    subItem.AttachTo( tab );

                    for ( int u = 0; u < 3; u++ )
                    {
                        var subItem2 = this.UnityContainer.Resolve<IMenuTreeEntry>();
                        subItem2.Title = "Submenu " + u.ToString();
                        subItem2.AttachTo( subItem );
                        subItem2.ActiveIconURI = @"pack://application:,,,/Tww.MAF.MAFMenuBarModule;component/RoundLabel177x104_Active.png";
                        subItem2.InActiveIconURI = @"pack://application:,,,/Tww.MAF.MAFMenuBarModule;component/RoundLabel177x104_InActive.png";
                    }
                }

                var service = this.UnityContainer.Resolve<IMenuBarService>();
                service.AddMenuEntry( tab );
            }

        }
    }
}
